package com.cherry.androidviewdemo.widget

import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.support.v7.widget.AppCompatImageView
import android.util.AttributeSet
import com.cherry.androidviewdemo.BuildConfig
import com.cherry.androidviewdemo.utils.sp2px

/**
 * @author DongMS
 * @since 2020/5/20
 */
class Sample01AfterOnDrawView : AppCompatImageView {

    private val paint: Paint = Paint(Paint.ANTI_ALIAS_FLAG)

    constructor (context: Context) : super(context)

    constructor(context: Context, attrs: AttributeSet?) : super(context, attrs)

    constructor(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)

    init {
        paint.color = Color.parseColor("#FFC107")
        paint.textSize = 14f.sp2px(context)
    }

    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)
        //在onDraw()后绘制
        if (BuildConfig.DEBUG) {
            canvas.save()
            canvas.concat(imageMatrix)
            val bounds = drawable.bounds
            canvas.drawText("图片尺寸:${bounds.width()}*${bounds.height()}", 20f, 40f, paint)
            canvas.restore()
        }
    }

}